
#include <cstdio>
#include "member_BScene.h"
#include "member_BShape.h"
#include "member_BNode.h"

using namespace BWE;

member_BScene::member_BScene(BScene* scene)
{
	boss = scene;
	refresh = false;
	dirtySpace = false;
}
member_BScene::~member_BScene()
{

}

void member_BScene::update(const BEvent& event)
{
	for (int i = 0; i < shapes.size(); i++)
	{
		BShape* shape = shapes[i];
		if (shape_member(shape)->dirty)
		{
			shape->flush();
		}
	}
	for (int i = 0; i < nodes.size(); i++)
	{
		BNode* node = nodes[i];
		node_member(node)->update(event);
		BShapeHolderArray& shapes = node_member(node)->shapes;
		for (int i = 0; i < shapes.size(); i++)
		{
			BShape* shape = shapes[i];
			if (shape_member(shape)->dirty)
			{
				shape->flush();
				node_member(node)->dirtyBox = true;
				node_member(node)->dirtySpace = true;
			}
		}
		if (node_member(node)->dirtySpace)
		{
			node->space();
		}
	}
	if (dirtySpace)
	{
		boss->space();
	}
}

void member_BScene::slotNodeFresh(BObject* object)
{
	refresh = true;
}
void member_BScene::slotShapeFresh(BObject* object)
{
	refresh = true;
}

void member_BScene::slotNodeDirty(BObject* object)
{
	refresh = true;
	dirtySpace = true;
}
void member_BScene::slotShapeDirty(BObject* object)
{
	refresh = true;
	dirtySpace = true;
}
